{template header common}
<script type="text/javascript" src="{__ROOT__}statics/js/haidao.validate.js?v={HD_VERSION}"></script>
<script type="text/javascript" src="{SKIN_PATH}statics/js/region-selection.js?v={HD_VERSION}"></script>
	<div class="mui-content">
	    <form name="ajax_district" action="{url('member/address/edit')}" method="POST">
	    	<div class="mui-input-group add-address">
		        <div class="mui-input-row">
		            <label>收货人</label>
		            <input type="text" class="mui-input-clear" value="{$address['name']}"  placeholder="请输入收货人" name="name"/>
		        </div>
		        <div class="mui-input-row">
		            <label>手机号码</label>
		            <input type="text" class="mui-input-clear" value="{$address['mobile']}" placeholder="请输入手机号码" name="mobile"/>
		        </div>
		        <div class="mui-input-row">
		            <label>邮政编码</label>
		            <input type="number" class="mui-input-clear" value="{$address['zipcode']}" placeholder="请输入邮政编码" name="zipcode"/>
		        </div>
		        <div class="mui-input-row">
		            <label>所在地区</label>
					<select class="mui-select" id="country"></select>
		        </div>
		        <div class="mui-input-row">
		            <label>所在省市</label>
		            <input class="mui-input" type="text" name="" value="" readonly="readonly" placeholder="请选择所在省市" id="choose-address" />
					<input class="district-text-id" type="hidden" name="district_id" value="{$address['district_id']}">
		        </div>
		        <div class="mui-input-row">
		            <label>详细地址</label> 
		            <input type="text" class="mui-input-clear" value="{$address['address']}" placeholder="请输入详细地址" name="address"/>
		        </div>
		    </div>
	    	<div class="padding">
				<input type="hidden" name="id" value="{$address[id]}" />
				<input type="hidden" name="default" value="{$address['isdefault']}" />
				<button type="submit" class="mui-btn mui-btn-primary full hd-h4">确认修改</button>
				<?php if($address['isdefault'] == 0){ ?>
	    		<button type="button" class="margin-top mui-btn mui-btn-primary full hd-h4 site-default">设为默认</button>
	    		<?php } ?>
	    		<button type="button" class="margin-top mui-btn mui-btn-danger full hd-h4 delete">删除收货地址</button>
	    	</div>
	    </form>
	</div>
	{template footer common}
</body>
</html>
<script>

var _referer = '{urldecode($_GET["referer"])}';
var ajax_district = $("form[name=ajax_district]").Validform({
	ajaxPost:true,
	callback:function(ret){
		if(ret.status == 1){
			$.tips({content:ret.message});
			var url = _referer || ret.referer;
			window.location.href = url;
		}else{
			$.tips({content:ret.message});
		}
	}
});

var gear = new gearArea();
gear.init({
	url: "{url('ajax_district')}",
	outer: document.getElementById("choose-address"),
	checkValue: "{$address['district_id']}",
	address: "{implode(" ",$address['full_district'])}",
	callback: function(ret){
		if(ret){
			var txt = '';
			for(var k in ret){
				$(".district-text-id").val(k);
				txt += ret[k] + " "
			}
			$("#choose-address").val(txt)
		}
	}
});


$(".delete").bind('click',function(){
	if(confirm('确定删除该地址')){
		var isdefault = "<?php echo $address['isdefault']?>";
		if(isdefault == 1){
			$.tips({content:'默认地址不能删除'});
			return false;
		}
		var ajaxurl = "<?php echo url('delete')?>";
		var id = "<?php echo $_GET['id']?>";
		$.post(ajaxurl,{id:id},function(ret){
			if(ret.status == 1){
				$.tips({content:ret.message});
				var url = _referer || ret.referer;
				window.location.href = url;
			}else{
				$.tips({content:ret.message});
			}
		},'json');
	}
})

$(".site-default").on('tap',function(){
	var id = "<?php echo $_GET['id']?>";
	$.post("{url('set_default')}", {id:id}, function(ret) {
		if(ret.status == 1){
			$.tips({content:ret.message});
			var url = _referer || ret.referer;
			window.location.href = url;
		}else{
			$.tips({content:ret.message});
		}
	}, 'json')
});

</script>
